class Agreement < ActiveRecord::Base
  
  after_create :generate_agreement_no
  
  belongs_to :customer
  belongs_to :user
  
  validates_presence_of :customer_id
  
  attr_accessor :user_log
  def to_audit
    return "ID:#{id}"+","+"Agreement NO.:#{agreement_no}"+","+"Customer Code:#{customer.code}"
  end
  
  private
  def generate_agreement_no
    self.agreement_no = Time.now.strftime("%Y")+"-"+"%05d"%self.id
    self.save
  end
  
end
